const randomString = require('./getRandom.js');
const enterNum = require('./enterNum.js');
function main(){
        let random = randomString();
        console.log("************随机数已生成**************")
        console.log(random);//显示所产生的随机数
        let yournumber = enterNum();//输入数字
        let result = yournumberVSrandom(yournumber,random);
        while(result !== '4A0B'){
            console.log("------------------")
            console.log(result);
            yournumber = enterNum();
            result = yournumberVSrandom(yournumber,random);
        }
        console.log(result);
        console.log("YOU WIN！");
}

function yournumberVSrandom(yournumber,random){
    let num1=0;
    let num2=0;
    let Length = yournumber.length;
    for(let index = 0;index < Length;index++){
        let value = yournumber[index];
        if(random.indexOf(value) !== -1){
            if(random.indexOf(value) === index){
               num1++;
            }else{
                num2++;
            }
        }
    }
    let judge_result = `${num1}A${num2}B`;
    return judge_result ;
}
module.exports = {
    yournumberVSrandom,main
}
main()
